package org.dey.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.dey.entity.Result;
import org.dey.mapper.RenqunfeileiMapper;
import org.dey.pojo.PageVo;
import org.dey.pojo.RenQunFenLei;
import org.dey.pojo.RiskAssessment;
import org.dey.service.RenqunfeileiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hg
 * @date 2022/4/6
 * @classname
 */
@Service
@Transactional
public class RenqunfeileiServiceImpl extends ServiceImpl<RenqunfeileiMapper, RenQunFenLei> implements RenqunfeileiService {

    @Autowired
    RenqunfeileiMapper renqunfeileiMapper;

    @Override
    public PageVo<RiskAssessment> renqunfeileiXx(int pageNum, int pagesize) {



        PageHelper.startPage(pageNum, pagesize);

        List<RiskAssessment> list =  renqunfeileiMapper.renqunfeileiXx();

        PageInfo<RiskAssessment> pageInfo = new PageInfo<RiskAssessment>(list);

        PageVo<RiskAssessment> pageVo = new PageVo<RiskAssessment>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }

    @Override
    public Result rqfl(int id1, int id2,int id3) {

        Result result = null;

        RenQunFenLei renqunfeilei = new RenQunFenLei();
        renqunfeilei.setMember(id1);
        renqunfeilei.setItid(id2);
        renqunfeilei.setZhuangtai("未干预");

        boolean save = this.save(renqunfeilei);
        if(save){
            //添加分类人群表数据成功 修改干预表状态
            int updaterazt = renqunfeileiMapper.updaterazt(id3);
              if(updaterazt==1){
                  result = new Result(true,"人群分类成功");
              }
        }else{
            result = new Result(true,"人群分类失败");
        }
        return result;
    }
}
